import {getItem} from "../services/LocalDataService";
import Config from "../Config";

// let typeIconMap: any = getItem("typeIconMap")

let iconMap: any = {
    organization: {
        getIcon: (data: any) => {
            switch (data.orgType) {
                case "Company":
                    return "icon-structure";
                case "Group":
                    return "icon-group";
                case "RoleInGroup":
                    return "icon-group";
                case "User":
                    return "icon-user";
            }
            return ""
        }
    },
    type: {
        getIcon: (key: string = "type", data: any) => {
            let typeIconMap: any = getItem(Config.localIcon);
            return typeIconMap[data[key]] || "";
        }
    }
};
// @ts-ignore
const getIconByData: Function = (key: string, data: any) => {
    let keys: string[] = key.split(".");
    return iconMap[keys[0]] ? iconMap[keys[0]].getIcon(keys[1], data) : (data[keys[0]] || "");
}

// @ts-ignore
const getIconByType: Function = (type: string) => {
    let typeIconMap: any = getItem(Config.localIcon);
    return typeIconMap[type] || "";
}

export {
    getIconByData,
    getIconByType
}
